﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SmallBasic.Library;

namespace Dozens4SmallBasic
{
    internal static class Extension
    {
        public static Primitive ToPrimitive(this DozensAPI.DozensZone[] zones)
        {
            var result = new Primitive();
            for (int i = 0; i < zones.Length; i++)
            {
                var row = new Primitive();
                row[1] = zones[i].Id;
                row[2] = zones[i].Name;
                result[i + 1] = row;
            }
            return result;
        }

        public static Primitive ToPrimitive(this DozensAPI.DozensRecord[] records)
        {
            var result = new Primitive();
            for (int i = 0; i < records.Length; i++)
            {
                var row = new Primitive();
                row[1] = records[i].Id;
                row[2] = records[i].Name;
                row[3] = records[i].Type;
                row[4] = records[i].Prio.HasValue ? new Primitive(records[i].Prio.Value) : new Primitive();
                row[5] = records[i].Content;
                row[6] = records[i].TTL;

                result[i + 1] = row;
            }
            return result;
        }
    }
}
